#include <iostream>
using namespace std;

int n;
const int N = 100001;
int arr[N];
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int ret = 0, i = 0;
    while (i < n)
    {
        if (i == n - 1)
        {
            ret++;
            break;
        }
        if (arr[i] < arr[i + 1])
        {
            while (i + 1 < n && arr[i] <= arr[i + 1]) i++;
            ret++;
        }
        else if (arr[i] > arr[i + 1])
        {
            while (i + 1 < n && arr[i] >= arr[i + 1]) i++;
            ret++;
        }
        else
        {
            while (i + 1 < n && arr[i] == arr[i + 1]) i++;
        }
        i++;
    }

    cout << ret << endl;
    return 0;
}

#include <iostream>
using namespace std;

int t, h;
int func()
{
    int ret = 0, a = 1;
    while (h)
    {
        h -= a;
        ret++;
        if (h % (a * 2) == 0)
        {
            a *= 2;
        }
    }
    return ret;
}
int main()
{
    cin >> t;
    while (t--)
    {
        cin >> h;
        cout << func() << endl;
    }
    return 0;
}